import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CategoryVO, CategoryForm, CategoryQuery } from './types';

// 定义返回数据类型
interface CategoryResponse {
  total: number;
  rows: CategoryVO[];
  code: number;
  msg: string;
}

/**
 * 查询CMS分类列表
 * @param query
 * @returns {*}
 */

export const listCategory = (query?: CategoryQuery): AxiosPromise<CategoryResponse> => {
  return request({
    url: '/cms/category/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询CMS分类详细
 * @param id
 */
export const getCategory = (id: string | number): AxiosPromise<CategoryVO> => {
  return request({
    url: '/cms/category/' + id,
    method: 'get'
  });
};

/**
 * 新增CMS分类
 * @param data
 */
export const addCategory = (data: CategoryForm) => {
  return request({
    url: '/cms/category',
    method: 'post',
    data: data
  });
};

/**
 * 修改CMS分类
 * @param data
 */
export const updateCategory = (data: CategoryForm) => {
  return request({
    url: '/cms/category',
    method: 'put',
    data: data
  });
};

/**
 * 删除CMS分类
 * @param id
 */
export const delCategory = (id: string | number | Array<string | number>) => {
  return request({
    url: '/cms/category/' + id,
    method: 'delete'
  });
};

/**
 * 获取模板列表
 */
export const getTemplatesList = (): AxiosPromise<string[]> => {
  return request({
    url: '/cms/category/getTemplatesList',
    method: 'get'
  });
};
